/*
 * 日志等级类
 *
 * 1. 定义日志等级枚举变量
 * 2. 定义日志等级变量转字符串的接口
 *
 **/

#pragma once

#include <string>
#include "except.hpp"

namespace easylog
{
    struct level
    {
        enum lv_enum
        {
            on = -1,
            debug,
            info,
            warn,
            error,
            fatal,
            off,
        };

        static std::string level2str(lv_enum lv)
        {
            switch (lv)
            {
            case debug: return "DEBUG";
            case info:  return "INFO";
            case warn:  return "WARN";
            case error: return "ERROR";
            case fatal: return "FATAL";
            case off:   return "OFF";
            default: throw except("level2str: illegal level");
            }
        }

        static lv_enum str2level(const std::string& s)
        {
            if      (s == "DEBUG") return debug;
            else if (s == "INFO")  return info;
            else if (s == "WARN")  return warn;
            else if (s == "ERROR") return error;
            else if (s == "FATAL") return fatal;
            else if (s == "OFF")   return off;
            else throw except("str2level: illegal level");
        }
    };
}
